﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ShareMarking.Systems.Service;
using ShareMarking.Service;
using ShareMarking.Entity;
using System.Configuration;
using System.Text.RegularExpressions;

namespace ShareMarking.Web.admin.EnterPrise.Activity
{
    public partial class Action : ManagePage
    {
        #region 属性=====================================
        private static string httpstr = ConfigurationManager.AppSettings["vigohttp"];
        private static string signsecret = ConfigurationManager.AppSettings["signscrect"];
        private static string diyhttp = ConfigurationManager.AppSettings["diyhttp"];//本系统网站域名

        /// <summary>
        /// 活动名称
        /// </summary>
        protected String Par_A_Name
        {
            get { return txt_A_Name.Text; }
            set { txt_A_Name.Text = value; }
        }

        /// <summary>
        /// 活动描述
        /// </summary>
        protected String Par_A_Desc
        {
            get { return txt_A_Desc.Text; }
            set { txt_A_Desc.Text = value; }
        }

        /// <summary>
        /// 负责人
        /// </summary>
        protected String Par_A_Manager
        {
            get { return Regex.Replace(txt_A_Manager.Text.ToString().Trim(), @"\s", ""); }
            set { txt_A_Manager.Text = value; }
        }
        /// <summary>
        /// 参数sacode
        /// </summary>
        protected String parsacode
        {
            get { return txtsacode.Text; }
            set { txtsacode.Text = value; }
        }
        /// <summary>
        /// 活动开始时间
        /// </summary>
        protected DateTime  ParStartTime
        {
            get { return txtStartTime.Text.ConvertTo<DateTime>(); }
            set { txtStartTime.Text = value.ToString("yyyy-MM-dd HH:mm:ss"); }
        }
        /// <summary>
        /// 活动结束时间
        /// </summary>
        protected DateTime ParEndTime
        {
            get { return txtEndTime.Text.ConvertTo<DateTime>(); }
            set { txtEndTime.Text = value.ToString("yyyy-MM-dd HH:mm:ss"); }
        }
        /// <summary>
        /// 子来源
        /// </summary>
        protected String Par_Chre_Source
        {
            get { return Regex.Replace(txt_Chre_Source.Text.ToString().Trim(), @"\s", ""); }
            set { txt_Chre_Source.Text = value; }
        }
        /// <summary>
        /// 指定代码
        /// </summary>
        protected String Par_Appoint_Code
        {
            get { return Regex.Replace(txt_Appoint_Code.Text.ToString().Trim(), @"\s", ""); }
            set { txt_Appoint_Code.Text = value; }
        }
        #region 图文1=====================================
        /// <summary>
        /// 微信图文标题
        /// </summary>
        protected String Par_A_wxTitle
        {
            get { return Regex.Replace(txt_A_wxTitle.Text.ToString().Trim(), @"\s", ""); }
            set { txt_A_wxTitle.Text = value; }
        }

        /// <summary>
        /// 微信图文图片
        /// </summary>
        protected String Par_A_wxImgUrl
        {
            get { return txt_A_wxImgUrl.Text; }
            set { txt_A_wxImgUrl.Text = value; }
        }
       
        /// <summary>
        /// 微信图文描述
        /// </summary>
        protected String Par_A_wxDesc
        {
            get { return txt_A_wxDesc.Text; }
            set { txt_A_wxDesc.Text = value; }
        }

        /// <summary>
        /// 活动中微信图文链接
        /// </summary>
        protected String Par_A_wxUrl
        {
            get { return txt_A_wxUrl.Text; }
            set { txt_A_wxUrl.Text = value; }
        }

        /// <summary>
        /// 活动前微信图文链接
        /// </summary>
        protected String Par_A_wxbeforeUrl
        {
            get { return txtbeforeurl.Text; }
            set { txtbeforeurl.Text = value; }
        }

        /// <summary>
        /// 活动后微信图文链接
        /// </summary>
        protected String Par_A_wxafterUrl
        {
            get { return txtafterurl.Text; }
            set { txtafterurl.Text = value; }
        }
        #endregion

        #region 图文2=====================================
        /// <summary>
        /// 微信图文标题2
        /// </summary>
        protected String Par_A_wxTitle2
        {
            get { return Regex.Replace(txt_A_wxTitle2.Text.ToString().Trim(), @"\s", ""); }
            set { txt_A_wxTitle2.Text = value; }
        }

        /// <summary>
        /// 微信图文图片2
        /// </summary>
        protected String Par_A_wxImgUrl2
        {
            get { return txt_A_wxImgUrl2.Text; }
            set { txt_A_wxImgUrl2.Text = value; }
        }

        /// <summary>
        /// 微信图文描述2
        /// </summary>
        protected String Par_A_wxDesc2
        {
            get { return txt_A_wxDesc2.Text; }
            set { txt_A_wxDesc2.Text = value; }
        }

        /// <summary>
        /// 活动中微信图文链接2
        /// </summary>
        protected String Par_A_wxUrl2
        {
            get { return txt_A_wxUrl2.Text; }
            set { txt_A_wxUrl2.Text = value; }
        }

        /// <summary>
        /// 活动前微信图文链接2
        /// </summary>
        protected String Par_A_wxbeforeUrl2
        {
            get { return txtbeforeurl2.Text; }
            set { txtbeforeurl2.Text = value; }
        }

        /// <summary>
        /// 活动后微信图文链接2
        /// </summary>
        protected String Par_A_wxafterUrl2
        {
            get { return txtafterurl2.Text; }
            set { txtafterurl2.Text = value; }
        }
        #endregion

        #region 图文3=====================================
        /// <summary>
        /// 微信图文标题3
        /// </summary>
        protected String Par_A_wxTitle3
        {
            get { return Regex.Replace(txt_A_wxTitle3.Text.ToString().Trim(), @"\s", ""); }
            set { txt_A_wxTitle3.Text = value; }
        }

        /// <summary>
        /// 微信图文图片3
        /// </summary>
        protected String Par_A_wxImgUrl3
        {
            get { return txt_A_wxImgUrl3.Text; }
            set { txt_A_wxImgUrl3.Text = value; }
        }

        /// <summary>
        /// 微信图文描述3
        /// </summary>
        protected String Par_A_wxDesc3
        {
            get { return txt_A_wxDesc3.Text; }
            set { txt_A_wxDesc3.Text = value; }
        }

        /// <summary>
        /// 活动中微信图文链接3
        /// </summary>
        protected String Par_A_wxUrl3
        {
            get { return txt_A_wxUrl3.Text; }
            set { txt_A_wxUrl3.Text = value; }
        }

        /// <summary>
        /// 活动前微信图文链接3
        /// </summary>
        protected String Par_A_wxbeforeUrl3
        {
            get { return txtbeforeurl3.Text; }
            set { txtbeforeurl3.Text = value; }
        }

        /// <summary>
        /// 活动后微信图文链接3
        /// </summary>
        protected String Par_A_wxafterUrl3
        {
            get { return txtafterurl3.Text; }
            set { txtafterurl3.Text = value; }
        }
        #endregion

        #region 图文4=====================================
        /// <summary>
        /// 微信图文标题4
        /// </summary>
        protected String Par_A_wxTitle4
        {
            get { return Regex.Replace(txt_A_wxTitle4.Text.ToString().Trim(), @"\s", ""); }
            set { txt_A_wxTitle4.Text = value; }
        }

        /// <summary>
        /// 微信图文图片4
        /// </summary>
        protected String Par_A_wxImgUrl4
        {
            get { return txt_A_wxImgUrl4.Text; }
            set { txt_A_wxImgUrl4.Text = value; }
        }

        /// <summary>
        /// 微信图文描述4
        /// </summary>
        protected String Par_A_wxDesc4
        {
            get { return txt_A_wxDesc4.Text; }
            set { txt_A_wxDesc4.Text = value; }
        }

        /// <summary>
        /// 活动中微信图文链接4
        /// </summary>
        protected String Par_A_wxUrl4
        {
            get { return txt_A_wxUrl4.Text; }
            set { txt_A_wxUrl4.Text = value; }
        }

        /// <summary>
        /// 活动前微信图文链接4
        /// </summary>
        protected String Par_A_wxbeforeUrl4
        {
            get { return txtbeforeurl4.Text; }
            set { txtbeforeurl4.Text = value; }
        }

        /// <summary>
        /// 活动后微信图文链接4
        /// </summary>
        protected String Par_A_wxafterUrl4
        {
            get { return txtafterurl4.Text; }
            set { txtafterurl4.Text = value; }
        }
        #endregion

        #region 图文5=====================================
        /// <summary>
        /// 微信图文标题5
        /// </summary>
        protected String Par_A_wxTitle5
        {
            get { return Regex.Replace(txt_A_wxTitle5.Text.ToString().Trim(), @"\s", ""); }
            set { txt_A_wxTitle5.Text = value; }
        }

        /// <summary>
        /// 微信图文图片5
        /// </summary>
        protected String Par_A_wxImgUrl5
        {
            get { return txt_A_wxImgUrl5.Text; }
            set { txt_A_wxImgUrl5.Text = value; }
        }

        /// <summary>
        /// 微信图文描述5
        /// </summary>
        protected String Par_A_wxDesc5
        {
            get { return txt_A_wxDesc5.Text; }
            set { txt_A_wxDesc5.Text = value; }
        }

        /// <summary>
        /// 活动中微信图文链接5
        /// </summary>
        protected String Par_A_wxUrl5
        {
            get { return txt_A_wxUrl5.Text; }
            set { txt_A_wxUrl5.Text = value; }
        }

        /// <summary>
        /// 活动前微信图文链接5
        /// </summary>
        protected String Par_A_wxbeforeUrl5
        {
            get { return txtbeforeurl5.Text; }
            set { txtbeforeurl5.Text = value; }
        }

        /// <summary>
        /// 活动后微信图文链接5
        /// </summary>
        protected String Par_A_wxafterUrl5
        {
            get { return txtafterurl5.Text; }
            set { txtafterurl5.Text = value; }
        }
        #endregion
        #endregion

        #region 初始化===================================

        protected string action = DTEnums.ActionEnum.Add.ToString(); //操作类型
        private int id = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            string _action = DTRequest.GetQueryString("action");
            if (!string.IsNullOrEmpty(_action) && _action == DTEnums.ActionEnum.Edit.ToString())
            {
                this.action = DTEnums.ActionEnum.Edit.ToString();//修改类型
                this.id = DTRequest.GetQueryInt("id");
                if (this.id == 0)
                {
                    JscriptMsg("传输参数不正确！", "back", "Error");
                    return;
                }
                if (!qr_ActivityService.Instance.Get_IsExist_ByWhere(qr_Activity._.ActivityID == this.id))
                {
                    JscriptMsg("信息不存在或已被删除！", "back", "Error");
                    return;
                }
            }
            if (!Page.IsPostBack)
            {
                //ChkAdminLevel("user_list", ShareMarkingEnums.ActionEnum.View.ToString()); //检查权限

                //绑定下拉框

                if (action == DTEnums.ActionEnum.Edit.ToString()) //修改
                {
                    ShowInfo(this.id);
                }
            }
        }

        #endregion

        #region 绑定下拉框===============================


        #endregion

        #region 赋值操作=================================
        private void ShowInfo(int _id)
        {
            ddl_U_ImageText.Items.Clear();//清除下拉内容
            
            #region 单图文信息
            var entity = qr_ActivityService.Instance.Get_SingleEntity_byWhere(qr_Activity._.ActivityID == _id);
            var relate = qr_QrCodeRelateService.Instance.Get_SingleEntity_byWhere(qr_QrCodeRelate._.qr_Type == 1000 && qr_QrCodeRelate._.IsDelete == false && qr_QrCodeRelate._.rel_Code == _id);
            if (entity == null) return;
            Par_A_Name = entity.A_Name;
            Par_A_Desc = entity.A_Desc;
            Par_A_Manager = entity.A_Manager;

            Par_A_wxTitle = entity.A_wxTitle;
            Par_A_wxImgUrl = entity.A_wxImgUrl;//
            this.iImagesurl.ImageUrl = entity.A_wxImgUrl;//
            Par_A_wxDesc = entity.A_wxDesc;
            Par_A_wxUrl = entity.A_wxUrl;
            Par_A_wxbeforeUrl = entity.A_wxbeforeUrl;
            Par_A_wxafterUrl = entity.A_wxafterUrl;

            parsacode = entity.A_SaCode;//
            ParStartTime = entity.A_StartTime.ConvertTo<DateTime>();
            ParEndTime = entity.A_EndTime.ConvertTo<DateTime>();
            if (relate!=null){
            Par_Appoint_Code = relate.Appoint_Code;
            Par_Chre_Source = relate.Chre_Source;
            }
            ddl_U_ImageText.Items.Add(new ListItem("单图文", "1"));
            ddl_U_ImageText.SelectedValue = "1";//默认是单图文
            #endregion

            #region 多图文信息
            var dt = qr_MoreActivityService.Instance.Get_Entity_byWhere_ToTable(qr_MoreActivity._.ActivityID == entity.ActivityID, qr_MoreActivity._.MA_Sort.Asc);
            if (dt == null)
            {
                return;
            }
            else
            {
                #region 循环判断显示条数
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string sort = dt.Rows[i]["MA_Sort"].ToString();//第几条图文从2开始
                    if (sort == "2")
                    {
                        Par_A_wxTitle2 = dt.Rows[i]["MA_wxTitle"].ToString();
                        Par_A_wxImgUrl2 = dt.Rows[i]["MA_wxImgUrl"].ToString();
                        this.iImagesurl2.ImageUrl = dt.Rows[i]["MA_wxImgUrl"].ToString();
                        Par_A_wxDesc2 = dt.Rows[i]["MA_wxDesc"].ToString();
                        Par_A_wxUrl2 = dt.Rows[i]["MA_wxUrl"].ToString();
                        Par_A_wxbeforeUrl2 = dt.Rows[i]["MA_wxbeforeUrl"].ToString();
                        Par_A_wxafterUrl2 = dt.Rows[i]["MA_wxafterUrl"].ToString();
                        ddl_U_ImageText.Items.Add(new ListItem("双图文", "2"));
                    }
                    else if (sort == "3")
                    {
                        Par_A_wxTitle3 = dt.Rows[i]["MA_wxTitle"].ToString();
                        Par_A_wxImgUrl3 = dt.Rows[i]["MA_wxImgUrl"].ToString();
                        this.iImagesurl3.ImageUrl = dt.Rows[i]["MA_wxImgUrl"].ToString();
                        Par_A_wxDesc3 = dt.Rows[i]["MA_wxDesc"].ToString();
                        Par_A_wxUrl3 = dt.Rows[i]["MA_wxUrl"].ToString();
                        Par_A_wxbeforeUrl3 = dt.Rows[i]["MA_wxbeforeUrl"].ToString();
                        Par_A_wxafterUrl3 = dt.Rows[i]["MA_wxafterUrl"].ToString();
                        ddl_U_ImageText.Items.Add(new ListItem("三图文", "3"));
                    }
                    else if (sort == "4")
                    {
                        Par_A_wxTitle4 = dt.Rows[i]["MA_wxTitle"].ToString();
                        Par_A_wxImgUrl4 = dt.Rows[i]["MA_wxImgUrl"].ToString();
                        this.iImagesurl4.ImageUrl = dt.Rows[i]["MA_wxImgUrl"].ToString();
                        Par_A_wxDesc4 = dt.Rows[i]["MA_wxDesc"].ToString();
                        Par_A_wxUrl4 = dt.Rows[i]["MA_wxUrl"].ToString();
                        Par_A_wxbeforeUrl4 = dt.Rows[i]["MA_wxbeforeUrl"].ToString();
                        Par_A_wxafterUrl4 = dt.Rows[i]["MA_wxafterUrl"].ToString();
                        ddl_U_ImageText.Items.Add(new ListItem("四图文", "4"));
                    }
                    else if (sort == "5")
                    {
                        Par_A_wxTitle5 = dt.Rows[i]["MA_wxTitle"].ToString();
                        Par_A_wxImgUrl5 = dt.Rows[i]["MA_wxImgUrl"].ToString();
                        this.iImagesurl5.ImageUrl = dt.Rows[i]["MA_wxImgUrl"].ToString();
                        Par_A_wxDesc5 = dt.Rows[i]["MA_wxDesc"].ToString();
                        Par_A_wxUrl5 = dt.Rows[i]["MA_wxUrl"].ToString();
                        Par_A_wxbeforeUrl5 = dt.Rows[i]["MA_wxbeforeUrl"].ToString();
                        Par_A_wxafterUrl5 = dt.Rows[i]["MA_wxafterUrl"].ToString();
                        ddl_U_ImageText.Items.Add(new ListItem("五图文", "5"));
                    }
                }
                #endregion
                int number = dt.Rows.Count + 1;//从MA_Sort=2开始。始终加1
                ddl_U_ImageText.SelectedValue = number.ToString(); ;//默认是单图文
                
                
            }
            #endregion
        }
        #endregion

        #region 增加操作=================================
        private bool DoAdd()
        {
            var result = false;
            try
            {
                #region 添加活动二维码

                #region 初始化变量
                var currenturl = "";
                var currenturl2 = "";
                var currenturl3 = "";
                var currenturl4 = "";
                var currenturl5 = "";
                List<ShareMarking.Interface.extra> extra = null;
                int sort = ddl_U_ImageText.SelectedValue.ConvertTo<int>();
                #endregion

                #region 判断图文链接

                if (DateTime.Now < ParStartTime)
                {
                    #region 根据选择的条数判断（活动前）URL
                    if (sort == 1)
                    {
                        currenturl = Regex.Replace(Par_A_wxbeforeUrl.ToString().Trim(), @"\s", "");//去掉链接URL的空字符串//Par_A_wxbeforeUrl;
                    }
                    else if (sort == 2)
                    {
                        currenturl = Regex.Replace(Par_A_wxbeforeUrl.ToString().Trim(), @"\s", "");
                        currenturl2 = Regex.Replace(Par_A_wxbeforeUrl2.ToString().Trim(), @"\s", "");
                    }
                    else if (sort == 3)
                    {
                        currenturl = Regex.Replace(Par_A_wxbeforeUrl.ToString().Trim(), @"\s", "");
                        currenturl2 = Regex.Replace(Par_A_wxbeforeUrl2.ToString().Trim(), @"\s", "");
                        currenturl3 = Regex.Replace(Par_A_wxbeforeUrl3.ToString().Trim(), @"\s", "");
                    }
                    else if (sort == 4)
                    {
                        currenturl = Regex.Replace(Par_A_wxbeforeUrl.ToString().Trim(), @"\s", "");
                        currenturl2 = Regex.Replace(Par_A_wxbeforeUrl2.ToString().Trim(), @"\s", "");
                        currenturl3 = Regex.Replace(Par_A_wxbeforeUrl3.ToString().Trim(), @"\s", "");
                        currenturl4 = Regex.Replace(Par_A_wxbeforeUrl4.ToString().Trim(), @"\s", "");
                    }
                    else if (sort == 5)
                    {
                        currenturl = Regex.Replace(Par_A_wxbeforeUrl.ToString().Trim(), @"\s", "");
                        currenturl2 = Regex.Replace(Par_A_wxbeforeUrl2.ToString().Trim(), @"\s", "");
                        currenturl3 = Regex.Replace(Par_A_wxbeforeUrl3.ToString().Trim(), @"\s", "");
                        currenturl4 = Regex.Replace(Par_A_wxbeforeUrl4.ToString().Trim(), @"\s", "");
                        currenturl5 = Regex.Replace(Par_A_wxbeforeUrl5.ToString().Trim(), @"\s", "");
                    }
                    #endregion
                }
                else if (DateTime.Now > ParStartTime && DateTime.Now < ParEndTime)
                {
                    #region 根据选择的条数判断（活动中）URL
                    if (sort == 1)
                    {
                        currenturl = Regex.Replace(Par_A_wxUrl.ToString().Trim(), @"\s", "");//去掉链接URL的空字符串//Par_A_wxbeforeUrl;
                    }
                    else if (sort == 2)
                    {
                        currenturl = Regex.Replace(Par_A_wxUrl.ToString().Trim(), @"\s", "");
                        currenturl2 = Regex.Replace(Par_A_wxUrl2.ToString().Trim(), @"\s", "");
                    }
                    else if (sort == 3)
                    {
                        currenturl = Regex.Replace(Par_A_wxUrl.ToString().Trim(), @"\s", "");
                        currenturl2 = Regex.Replace(Par_A_wxUrl2.ToString().Trim(), @"\s", "");
                        currenturl3 = Regex.Replace(Par_A_wxUrl3.ToString().Trim(), @"\s", "");
                    }
                    else if (sort == 4)
                    {
                        currenturl = Regex.Replace(Par_A_wxUrl.ToString().Trim(), @"\s", "");
                        currenturl2 = Regex.Replace(Par_A_wxUrl2.ToString().Trim(), @"\s", "");
                        currenturl3 = Regex.Replace(Par_A_wxUrl3.ToString().Trim(), @"\s", "");
                        currenturl4 = Regex.Replace(Par_A_wxUrl4.ToString().Trim(), @"\s", "");
                    }
                    else if (sort == 5)
                    {
                        currenturl = Regex.Replace(Par_A_wxUrl.ToString().Trim(), @"\s", "");
                        currenturl2 = Regex.Replace(Par_A_wxUrl2.ToString().Trim(), @"\s", "");
                        currenturl3 = Regex.Replace(Par_A_wxUrl3.ToString().Trim(), @"\s", "");
                        currenturl4 = Regex.Replace(Par_A_wxUrl4.ToString().Trim(), @"\s", "");
                        currenturl5 = Regex.Replace(Par_A_wxUrl5.ToString().Trim(), @"\s", "");
                    }
                    #endregion
                }
                else
                {                   
                    #region 根据选择的条数判断（活动后）URL
                    if (sort == 1)
                    {
                        currenturl = Regex.Replace(Par_A_wxafterUrl.ToString().Trim(), @"\s", "");//去掉链接URL的空字符串//Par_A_wxbeforeUrl;
                    }
                    else if (sort == 2)
                    {
                        currenturl = Regex.Replace(Par_A_wxafterUrl.ToString().Trim(), @"\s", "");
                        currenturl2 = Regex.Replace(Par_A_wxafterUrl2.ToString().Trim(), @"\s", "");
                    }
                    else if (sort == 3)
                    {
                        currenturl = Regex.Replace(Par_A_wxafterUrl.ToString().Trim(), @"\s", "");
                        currenturl2 = Regex.Replace(Par_A_wxafterUrl2.ToString().Trim(), @"\s", "");
                        currenturl3 = Regex.Replace(Par_A_wxafterUrl3.ToString().Trim(), @"\s", "");
                    }
                    else if (sort == 4)
                    {
                        currenturl = Regex.Replace(Par_A_wxafterUrl.ToString().Trim(), @"\s", "");
                        currenturl2 = Regex.Replace(Par_A_wxafterUrl2.ToString().Trim(), @"\s", "");
                        currenturl3 = Regex.Replace(Par_A_wxafterUrl3.ToString().Trim(), @"\s", "");
                        currenturl4 = Regex.Replace(Par_A_wxafterUrl4.ToString().Trim(), @"\s", "");
                    }
                    else if (sort == 5)
                    {
                        currenturl = Regex.Replace(Par_A_wxafterUrl.ToString().Trim(), @"\s", "");
                        currenturl2 = Regex.Replace(Par_A_wxafterUrl2.ToString().Trim(), @"\s", "");
                        currenturl3 = Regex.Replace(Par_A_wxafterUrl3.ToString().Trim(), @"\s", "");
                        currenturl4 = Regex.Replace(Par_A_wxafterUrl4.ToString().Trim(), @"\s", "");
                        currenturl5 = Regex.Replace(Par_A_wxafterUrl5.ToString().Trim(), @"\s", "");
                    }
                    #endregion
                }
                //if (Par_Chre_Source.IsNullOrEmpty()) {
                //    JscriptMsg("子来源不能为空！", "", "Error");
                //}
                //if (Par_Appoint_Code.IsNullOrEmpty())
                //{
                //    JscriptMsg("指定代码不能为空！", "", "Error");
                //}

                var ssacode = "";
                if (currenturl.Contains("?") || currenturl2.Contains("?") || currenturl3.Contains("?") || currenturl4.Contains("?") || currenturl5.Contains("?"))
                {
                    ssacode = "$sacode=" + Regex.Replace(parsacode.ToString().Trim(), @"\s", "");
                }
                else
                {
                    ssacode = "?sacode=" + Regex.Replace(parsacode.ToString().Trim(), @"\s", "");
                }
                #endregion

                #region 组装消息
                var sceneid = 0;
                qr_QrCodeType type = qr_QrCodeTypeService.Instance.Get_SingleEntity_byWhere(qr_QrCodeType._.QrCodeTypeID == 1000);
                sceneid = type.QT_CurrentIndex.ConvertTo<int>() + 1;                
                if (sort > 0)
                {
                    #region 单图文
                    if (sort == 1)
                    {
                        extra = new List<ShareMarking.Interface.extra>() { 
                    new ShareMarking.Interface.extra { 
                        title = Par_A_wxTitle, 
                        shortdesc = Par_A_wxDesc, 
                        linkurl = (currenturl).Replace('&','$'),
                        picurl =diyhttp+ Par_A_wxImgUrl
                    }
                };
                    }
                    #endregion

                    #region 双图文
                    else if (sort == 2)
                    {
                        extra = new List<ShareMarking.Interface.extra>() { 
                            new ShareMarking.Interface.extra { 
                                title = Par_A_wxTitle, 
                                shortdesc = Par_A_wxDesc, 
                                linkurl = (currenturl).Replace('&','$'),
                                picurl =diyhttp+ Par_A_wxImgUrl
                            },
                            new ShareMarking.Interface.extra { 
                                title = Par_A_wxTitle2, 
                                shortdesc = Par_A_wxDesc2, 
                                linkurl = (currenturl2).Replace('&','$'),
                                picurl =diyhttp+ Par_A_wxImgUrl2
                            }
                        };
                    }
                    #endregion

                    #region 三图文
                    else if (sort == 3)
                    {
                        extra = new List<ShareMarking.Interface.extra>() { 
                            new ShareMarking.Interface.extra { 
                                title = Par_A_wxTitle, 
                                shortdesc = Par_A_wxDesc, 
                                linkurl = (currenturl).Replace('&','$'),
                                picurl =diyhttp+ Par_A_wxImgUrl
                            },
                            new ShareMarking.Interface.extra { 
                                title = Par_A_wxTitle2, 
                                shortdesc = Par_A_wxDesc2, 
                                linkurl = (currenturl2).Replace('&','$'),
                                picurl =diyhttp+ Par_A_wxImgUrl2
                            },
                            new ShareMarking.Interface.extra { 
                                title = Par_A_wxTitle3, 
                                shortdesc = Par_A_wxDesc3, 
                                linkurl = (currenturl3).Replace('&','$'),
                                picurl =diyhttp+ Par_A_wxImgUrl3
                            }
                        };
                    }
                    #endregion

                    #region 四图文
                    else if (sort == 4)
                    {
                        extra = new List<ShareMarking.Interface.extra>() { 
                            new ShareMarking.Interface.extra { 
                                title = Par_A_wxTitle, 
                                shortdesc = Par_A_wxDesc, 
                                linkurl = (currenturl).Replace('&','$'),
                                picurl =diyhttp+ Par_A_wxImgUrl
                            },
                            new ShareMarking.Interface.extra { 
                                title = Par_A_wxTitle2, 
                                shortdesc = Par_A_wxDesc2, 
                                linkurl = (currenturl2).Replace('&','$'),
                                picurl =diyhttp+ Par_A_wxImgUrl2
                            },
                            new ShareMarking.Interface.extra { 
                                title = Par_A_wxTitle3, 
                                shortdesc = Par_A_wxDesc3, 
                                linkurl = (currenturl3).Replace('&','$'),
                                picurl =diyhttp+ Par_A_wxImgUrl3
                            },
                            new ShareMarking.Interface.extra { 
                                title = Par_A_wxTitle4, 
                                shortdesc = Par_A_wxDesc4, 
                                linkurl = (currenturl4).Replace('&','$'),
                                picurl =diyhttp+ Par_A_wxImgUrl4
                            }
                        };
                    }
                    #endregion

                    #region 五图文
                    else if (sort == 5)
                    {
                        extra = new List<ShareMarking.Interface.extra>() { 
                            new ShareMarking.Interface.extra { 
                                title = Par_A_wxTitle, 
                                shortdesc = Par_A_wxDesc, 
                                linkurl = (currenturl).Replace('&','$'),
                                picurl =diyhttp+ Par_A_wxImgUrl
                            },
                            new ShareMarking.Interface.extra { 
                                title = Par_A_wxTitle2, 
                                shortdesc = Par_A_wxDesc2, 
                                linkurl = (currenturl2).Replace('&','$'),
                                picurl =diyhttp+ Par_A_wxImgUrl2
                            },
                            new ShareMarking.Interface.extra { 
                                title = Par_A_wxTitle3, 
                                shortdesc = Par_A_wxDesc3, 
                                linkurl = (currenturl3).Replace('&','$'),
                                picurl =diyhttp+ Par_A_wxImgUrl3
                            },
                            new ShareMarking.Interface.extra { 
                                title = Par_A_wxTitle4, 
                                shortdesc = Par_A_wxDesc4, 
                                linkurl = (currenturl4).Replace('&','$'),
                                picurl =diyhttp+ Par_A_wxImgUrl4
                            },
                            new ShareMarking.Interface.extra { 
                                title = Par_A_wxTitle5, 
                                shortdesc = Par_A_wxDesc5, 
                                linkurl = (currenturl5).Replace('&','$'),
                                picurl =diyhttp+ Par_A_wxImgUrl5
                            }
                        };
                    }
                    #endregion                   

                }
                var message = new ShareMarking.Interface.message()
                {
                    title = Par_A_Name,
                    remark = Par_A_Name + "的二维码",
                    sacode = "test",
                    scene_id = sceneid,
                    extra = extra
                };
                #endregion

                #region vigo接口申请
                var vigo = new ShareMarking.Interface.Qrcode_vigo(httpstr, signsecret);
                var resultentity = vigo.CreateQrcode(message);
                #endregion

                #region 自增sceneid重新请求直到成功为止
                while (resultentity.errcode == "12")
                {
                    ComLib.LogLib.Log4NetBase.Log("错误信息:" + resultentity.errmsg + "/sceneid=" + sceneid);
                    sceneid += 1;
                    message.scene_id = sceneid;
                    resultentity = vigo.CreateQrcode(message);
                }
                #endregion

                #region 判断请求是否成功
                if (resultentity.errcode == "00")
                {
                    #region 保存二维码到数据库
                    qr_QrCode qrcode = new qr_QrCode()
                    {
                        id = resultentity.message.id,
                        type = 1000,
                        scene_id = resultentity.message.scene_id,
                        sacode = resultentity.message.sacode,
                        title = resultentity.message.title,
                        remark = resultentity.message.remark,
                        code_url = resultentity.message.code_url,
                        qrcode_url = resultentity.message.qrcode_url,
                        addtime = resultentity.message.addtime,
                        status = resultentity.message.status,
                        isdelete = false
                    };
                    qr_QrCodeService.Instance.Add_Entity(qrcode);
                    #endregion

                    string ActivityID = "";
                    if (sort == 1)
                    {
                        #region 保存单图文活动
                        var entity = new qr_Activity();
                        entity.A_Name = Regex.Replace(Par_A_Name.ToString().Trim(), @"\s", "");
                        entity.A_Desc = Par_A_Desc;
                        entity.A_Manager = Par_A_Manager;
                        entity.A_wxQrCodeID = resultentity.message.id.ToString();
                        entity.A_wxSceneID = resultentity.message.scene_id.ToString();
                        entity.A_wxTitle = Par_A_wxTitle;
                        entity.A_wxImgUrl = Par_A_wxImgUrl;//
                        entity.A_wxDesc = Par_A_wxDesc;
                        entity.A_wxUrl = Par_A_wxUrl;
                        entity.A_wxbeforeUrl = Par_A_wxbeforeUrl;
                        entity.A_wxafterUrl = Par_A_wxafterUrl;
                        entity.A_SaCode = parsacode;
                        entity.A_StartTime = ParStartTime;
                        entity.A_EndTime = ParEndTime;
                        entity.CreateOn = DateTime.Now;
                        entity.isneedupdate = false;
                        entity.A_currentUrl = currenturl;//当前时间的currurl
                        entity.isSenate = 1;//有参标识
                        qr_ActivityService.Instance.Add_Entity(entity);
                        ActivityID = entity.ActivityID.ToString();
                        #endregion
                    }
                    else if (sort == 2)
                    {
                        #region 保存第一条图文活动
                        var entity = new qr_Activity();
                        entity.A_Name = Regex.Replace(Par_A_Name.ToString().Trim(), @"\s", "");
                        entity.A_Desc = Par_A_Desc;
                        entity.A_Manager = Par_A_Manager;
                        entity.A_wxQrCodeID = resultentity.message.id.ToString();
                        entity.A_wxSceneID = resultentity.message.scene_id.ToString();
                        entity.A_wxTitle = Par_A_wxTitle;
                        entity.A_wxImgUrl = Par_A_wxImgUrl;//
                        entity.A_wxDesc = Par_A_wxDesc;
                        entity.A_wxUrl = Par_A_wxUrl;
                        entity.A_wxbeforeUrl = Par_A_wxbeforeUrl;
                        entity.A_wxafterUrl = Par_A_wxafterUrl;
                        entity.A_SaCode = parsacode;
                        entity.A_StartTime = ParStartTime;
                        entity.A_EndTime = ParEndTime;
                        entity.CreateOn = DateTime.Now;
                        entity.isneedupdate = false;
                        entity.A_currentUrl = currenturl;//当前时间的currurl
                        entity.isSenate = 1;//有参标识
                        qr_ActivityService.Instance.Add_Entity(entity);
                        ActivityID = entity.ActivityID.ToString();
                        #endregion

                        #region 保存第二条图文活动
                        var entity2 = new qr_MoreActivity();
                        entity2.ActivityID = entity.ActivityID;//关联第一条图文ID
                        entity2.MA_Sort = 2;//当前是第二条图文信息
                        entity2.MA_wxTitle = Par_A_wxTitle2;
                        entity2.MA_wxImgUrl = Par_A_wxImgUrl2;
                        entity2.MA_wxDesc = Par_A_wxDesc2;
                        entity2.MA_wxUrl = Par_A_wxUrl2;
                        entity2.MA_wxbeforeUrl = Par_A_wxbeforeUrl2;
                        entity2.MA_wxafterUrl = Par_A_wxafterUrl2;
                        entity2.CreateOn = DateTime.Now;
                        entity2.MA_currentUrl = currenturl;//当前时间的currurl
                        qr_MoreActivityService.Instance.Add_Entity(entity2);
                        #endregion
                    }
                    else if (sort == 3)
                    {
                        #region 保存第一条图文活动
                        var entity = new qr_Activity();
                        entity.A_Name = Regex.Replace(Par_A_Name.ToString().Trim(), @"\s", "");
                        entity.A_Desc = Par_A_Desc;
                        entity.A_Manager = Par_A_Manager;
                        entity.A_wxQrCodeID = resultentity.message.id.ToString();
                        entity.A_wxSceneID = resultentity.message.scene_id.ToString();
                        entity.A_wxTitle = Par_A_wxTitle;
                        entity.A_wxImgUrl = Par_A_wxImgUrl;//
                        entity.A_wxDesc = Par_A_wxDesc;
                        entity.A_wxUrl = Par_A_wxUrl;
                        entity.A_wxbeforeUrl = Par_A_wxbeforeUrl;
                        entity.A_wxafterUrl = Par_A_wxafterUrl;
                        entity.A_SaCode = parsacode;
                        entity.A_StartTime = ParStartTime;
                        entity.A_EndTime = ParEndTime;
                        entity.CreateOn = DateTime.Now;
                        entity.isneedupdate = false;
                        entity.A_currentUrl = currenturl;//当前时间的currurl
                        entity.isSenate = 1;//有参标识
                        qr_ActivityService.Instance.Add_Entity(entity);
                        ActivityID = entity.ActivityID.ToString();
                        #endregion

                        #region 保存第二条图文活动
                        var entity2 = new qr_MoreActivity();
                        entity2.ActivityID = entity.ActivityID;//关联第一条图文ID
                        entity2.MA_Sort = 2;//当前是第二条图文信息
                        entity2.MA_wxTitle = Par_A_wxTitle2;
                        entity2.MA_wxImgUrl = Par_A_wxImgUrl2;
                        entity2.MA_wxDesc = Par_A_wxDesc2;
                        entity2.MA_wxUrl = Par_A_wxUrl2;
                        entity2.MA_wxbeforeUrl = Par_A_wxbeforeUrl2;
                        entity2.MA_wxafterUrl = Par_A_wxafterUrl2;
                        entity2.CreateOn = DateTime.Now;
                        entity2.MA_currentUrl = currenturl;//当前时间的currurl
                        qr_MoreActivityService.Instance.Add_Entity(entity2);
                        #endregion

                        #region 保存第三条图文活动
                        var entity3 = new qr_MoreActivity();
                        entity3.ActivityID = entity.ActivityID;//关联第一条图文ID
                        entity3.MA_Sort = 3;//当前是第三条图文信息
                        entity3.MA_wxTitle = Par_A_wxTitle3;
                        entity3.MA_wxImgUrl = Par_A_wxImgUrl3;
                        entity3.MA_wxDesc = Par_A_wxDesc3;
                        entity3.MA_wxUrl = Par_A_wxUrl3;
                        entity3.MA_wxbeforeUrl = Par_A_wxbeforeUrl3;
                        entity3.MA_wxafterUrl = Par_A_wxafterUrl3;
                        entity3.CreateOn = DateTime.Now;
                        entity3.MA_currentUrl = currenturl;//当前时间的currurl
                        qr_MoreActivityService.Instance.Add_Entity(entity3);
                        #endregion
                    }
                    else if (sort == 4)
                    {
                        #region 保存第一条图文活动
                        var entity = new qr_Activity();
                        entity.A_Name = Regex.Replace(Par_A_Name.ToString().Trim(), @"\s", "");
                        entity.A_Desc = Par_A_Desc;
                        entity.A_Manager = Par_A_Manager;
                        entity.A_wxQrCodeID = resultentity.message.id.ToString();
                        entity.A_wxSceneID = resultentity.message.scene_id.ToString();
                        entity.A_wxTitle = Par_A_wxTitle;
                        entity.A_wxImgUrl = Par_A_wxImgUrl;//
                        entity.A_wxDesc = Par_A_wxDesc;
                        entity.A_wxUrl = Par_A_wxUrl;
                        entity.A_wxbeforeUrl = Par_A_wxbeforeUrl;
                        entity.A_wxafterUrl = Par_A_wxafterUrl;
                        entity.A_SaCode = parsacode;
                        entity.A_StartTime = ParStartTime;
                        entity.A_EndTime = ParEndTime;
                        entity.CreateOn = DateTime.Now;
                        entity.isneedupdate = false;
                        entity.A_currentUrl = currenturl;//当前时间的currurl
                        entity.isSenate = 1;//有参标识
                        qr_ActivityService.Instance.Add_Entity(entity);
                        ActivityID = entity.ActivityID.ToString();
                        #endregion

                        #region 保存第二条图文活动
                        var entity2 = new qr_MoreActivity();
                        entity2.ActivityID = entity.ActivityID;//关联第一条图文ID
                        entity2.MA_Sort = 2;//当前是第二条图文信息
                        entity2.MA_wxTitle = Par_A_wxTitle2;
                        entity2.MA_wxImgUrl = Par_A_wxImgUrl2;
                        entity2.MA_wxDesc = Par_A_wxDesc2;
                        entity2.MA_wxUrl = Par_A_wxUrl2;
                        entity2.MA_wxbeforeUrl = Par_A_wxbeforeUrl2;
                        entity2.MA_wxafterUrl = Par_A_wxafterUrl2;
                        entity2.CreateOn = DateTime.Now;
                        entity2.MA_currentUrl = currenturl;//当前时间的currurl
                        qr_MoreActivityService.Instance.Add_Entity(entity2);
                        #endregion

                        #region 保存第三条图文活动
                        var entity3 = new qr_MoreActivity();
                        entity3.ActivityID = entity.ActivityID;//关联第一条图文ID
                        entity3.MA_Sort = 3;//当前是第三条图文信息
                        entity3.MA_wxTitle = Par_A_wxTitle3;
                        entity3.MA_wxImgUrl = Par_A_wxImgUrl3;
                        entity3.MA_wxDesc = Par_A_wxDesc3;
                        entity3.MA_wxUrl = Par_A_wxUrl3;
                        entity3.MA_wxbeforeUrl = Par_A_wxbeforeUrl3;
                        entity3.MA_wxafterUrl = Par_A_wxafterUrl3;
                        entity3.CreateOn = DateTime.Now;
                        entity3.MA_currentUrl = currenturl;//当前时间的currurl
                        qr_MoreActivityService.Instance.Add_Entity(entity3);
                        #endregion

                        #region 保存第四条图文活动
                        var entity4 = new qr_MoreActivity();
                        entity4.ActivityID = entity.ActivityID;//关联第一条图文ID
                        entity4.MA_Sort = 4;//当前是第四条图文信息
                        entity4.MA_wxTitle = Par_A_wxTitle4;
                        entity4.MA_wxImgUrl = Par_A_wxImgUrl4;
                        entity4.MA_wxDesc = Par_A_wxDesc4;
                        entity4.MA_wxUrl = Par_A_wxUrl4;
                        entity4.MA_wxbeforeUrl = Par_A_wxbeforeUrl4;
                        entity4.MA_wxafterUrl = Par_A_wxafterUrl4;
                        entity4.CreateOn = DateTime.Now;
                        entity4.MA_currentUrl = currenturl;//当前时间的currurl
                        qr_MoreActivityService.Instance.Add_Entity(entity4);
                        #endregion
                    }
                    else if (sort == 5)
                    {
                        #region 保存第一条图文活动
                        var entity = new qr_Activity();
                        entity.A_Name = Regex.Replace(Par_A_Name.ToString().Trim(), @"\s", "");
                        entity.A_Desc = Par_A_Desc;
                        entity.A_Manager = Par_A_Manager;
                        entity.A_wxQrCodeID = resultentity.message.id.ToString();
                        entity.A_wxSceneID = resultentity.message.scene_id.ToString();
                        entity.A_wxTitle = Par_A_wxTitle;
                        entity.A_wxImgUrl = Par_A_wxImgUrl;//
                        entity.A_wxDesc = Par_A_wxDesc;
                        entity.A_wxUrl = Par_A_wxUrl;
                        entity.A_wxbeforeUrl = Par_A_wxbeforeUrl;
                        entity.A_wxafterUrl = Par_A_wxafterUrl;
                        entity.A_SaCode = parsacode;
                        entity.A_StartTime = ParStartTime;
                        entity.A_EndTime = ParEndTime;
                        entity.CreateOn = DateTime.Now;
                        entity.isneedupdate = false;
                        entity.A_currentUrl = currenturl;//当前时间的currurl
                        entity.isSenate = 1;//有参标识
                        qr_ActivityService.Instance.Add_Entity(entity);
                        ActivityID = entity.ActivityID.ToString();
                        #endregion

                        #region 保存第二条图文活动
                        var entity2 = new qr_MoreActivity();
                        entity2.ActivityID = entity.ActivityID;//关联第一条图文ID
                        entity2.MA_Sort = 2;//当前是第二条图文信息
                        entity2.MA_wxTitle = Par_A_wxTitle2;
                        entity2.MA_wxImgUrl = Par_A_wxImgUrl2;
                        entity2.MA_wxDesc = Par_A_wxDesc2;
                        entity2.MA_wxUrl = Par_A_wxUrl2;
                        entity2.MA_wxbeforeUrl = Par_A_wxbeforeUrl2;
                        entity2.MA_wxafterUrl = Par_A_wxafterUrl2;
                        entity2.CreateOn = DateTime.Now;
                        entity2.MA_currentUrl = currenturl;//当前时间的currurl
                        qr_MoreActivityService.Instance.Add_Entity(entity2);
                        #endregion

                        #region 保存第三条图文活动
                        var entity3 = new qr_MoreActivity();
                        entity3.ActivityID = entity.ActivityID;//关联第一条图文ID
                        entity3.MA_Sort = 3;//当前是第三条图文信息
                        entity3.MA_wxTitle = Par_A_wxTitle3;
                        entity3.MA_wxImgUrl = Par_A_wxImgUrl3;
                        entity3.MA_wxDesc = Par_A_wxDesc3;
                        entity3.MA_wxUrl = Par_A_wxUrl3;
                        entity3.MA_wxbeforeUrl = Par_A_wxbeforeUrl3;
                        entity3.MA_wxafterUrl = Par_A_wxafterUrl3;
                        entity3.CreateOn = DateTime.Now;
                        entity3.MA_currentUrl = currenturl;//当前时间的currurl
                        qr_MoreActivityService.Instance.Add_Entity(entity3);
                        #endregion

                        #region 保存第四条图文活动
                        var entity4 = new qr_MoreActivity();
                        entity4.ActivityID = entity.ActivityID;//关联第一条图文ID
                        entity4.MA_Sort = 4;//当前是第四条图文信息
                        entity4.MA_wxTitle = Par_A_wxTitle4;
                        entity4.MA_wxImgUrl = Par_A_wxImgUrl4;
                        entity4.MA_wxDesc = Par_A_wxDesc4;
                        entity4.MA_wxUrl = Par_A_wxUrl4;
                        entity4.MA_wxbeforeUrl = Par_A_wxbeforeUrl4;
                        entity4.MA_wxafterUrl = Par_A_wxafterUrl4;
                        entity4.CreateOn = DateTime.Now;
                        entity4.MA_currentUrl = currenturl;//当前时间的currurl
                        qr_MoreActivityService.Instance.Add_Entity(entity4);
                        #endregion

                        #region 保存第五条图文活动
                        var entity5 = new qr_MoreActivity();
                        entity5.ActivityID = entity.ActivityID;//关联第一条图文ID
                        entity5.MA_Sort = 5;//当前是第五条图文信息
                        entity5.MA_wxTitle = Par_A_wxTitle5;
                        entity5.MA_wxImgUrl = Par_A_wxImgUrl5;
                        entity5.MA_wxDesc = Par_A_wxDesc5;
                        entity5.MA_wxUrl = Par_A_wxUrl5;
                        entity5.MA_wxbeforeUrl = Par_A_wxbeforeUrl5;
                        entity5.MA_wxafterUrl = Par_A_wxafterUrl5;
                        entity5.CreateOn = DateTime.Now;
                        entity5.MA_currentUrl = currenturl;//当前时间的currurl
                        qr_MoreActivityService.Instance.Add_Entity(entity5);
                        #endregion
                    }

                    #region 添加关联
                    qr_QrCodeRelate qrrelate = new qr_QrCodeRelate()
                    {
                        qr_Type = 1000,//1000是活动
                        qr_CodeID = resultentity.message.id,
                        qr_Scene_ID = resultentity.message.scene_id,
                        rel_Code = ActivityID,
                        IsDelete = false,
                        CreateOn = DateTime.Now,
                        Chre_Source=Par_Chre_Source,
                        Appoint_Code = Par_Appoint_Code
                    };
                    qr_QrCodeRelateService.Instance.Add_Entity(qrrelate);
                    #endregion

                    #region 更改二维码类型表
                    type.QT_CurrentIndex = sceneid;
                    type.QT_Used = type.QT_Used + 1;
                    type.QT_Surplus = type.QT_Surplus - 1;
                    result = qr_QrCodeTypeService.Instance.Update_Entity(type);
                    #endregion

                }
                else
                {
                    ComLib.LogLib.Log4NetBase.Log("错误信息:" + resultentity.errmsg + "状态码:" + resultentity.errcode);
                }
                #endregion

                #endregion

                if (result)
                {
                    AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加qr_Activity"); //记录日志
                }
            }
            catch (Exception ex)
            {
                ComLib.LogLib.Log4NetBase.Log("新增活动错误::::" + ex.Message + ex.StackTrace);
            }
            return result;
        }
        #endregion

        #region 修改操作=================================
        private bool DoEdit(int _id)
        {

            var entity = qr_ActivityService.Instance.Get_SingleEntity_byWhere(qr_Activity._.ActivityID == _id);
            if (entity == null) return false;            
            #region 判断是否存在关联数据
            var dt = qr_MoreActivityService.Instance.Get_Entity_byWhere_ToTable(qr_MoreActivity._.ActivityID == entity.ActivityID, qr_MoreActivity._.MA_Sort.Asc);
            List<MoreActivity> alist = new List<MoreActivity>();
            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    MoreActivity MoreActivity = new MoreActivity()
                    {
                        ID = dt.Rows[i]["id"].ConvertTo<int>(),
                        Sortnumber = dt.Rows[i]["MA_Sort"].ConvertTo<int>(),
                    };
                    alist.Add(MoreActivity);
                }
            }
            var relate = qr_QrCodeRelateService.Instance.Get_SingleEntity_byWhere(
                                qr_QrCodeRelate._.qr_Type == 1000 && qr_QrCodeRelate._.IsDelete == false
                                && qr_QrCodeRelate._.rel_Code == entity.ActivityID);
            #endregion
            
     
            var result = false;
            try
            {
                if (relate != null)
                {
                    #region 修改活动二维码
                    #region 初始化变量
                    var currenturl = "";
                    var currenturl2 = "";
                    var currenturl3 = "";
                    var currenturl4 = "";
                    var currenturl5 = "";
                    List<ShareMarking.Interface.extra> extra = null;
                    int sort = ddl_U_ImageText.SelectedValue.ConvertTo<int>();
                    #endregion

                    #region 判断图文链接

                    if (DateTime.Now < ParStartTime)
                    {
                        #region 根据选择的条数判断（活动前）URL
                        if (sort == 1)
                        {
                            currenturl = Regex.Replace(Par_A_wxbeforeUrl.ToString().Trim(), @"\s", "");//去掉链接URL的空字符串//Par_A_wxbeforeUrl;
                        }
                        else if (sort == 2)
                        {
                            currenturl = Regex.Replace(Par_A_wxbeforeUrl.ToString().Trim(), @"\s", "");
                            currenturl2 = Regex.Replace(Par_A_wxbeforeUrl2.ToString().Trim(), @"\s", "");
                        }
                        else if (sort == 3)
                        {
                            currenturl = Regex.Replace(Par_A_wxbeforeUrl.ToString().Trim(), @"\s", "");
                            currenturl2 = Regex.Replace(Par_A_wxbeforeUrl2.ToString().Trim(), @"\s", "");
                            currenturl3 = Regex.Replace(Par_A_wxbeforeUrl3.ToString().Trim(), @"\s", "");
                        }
                        else if (sort == 4)
                        {
                            currenturl = Regex.Replace(Par_A_wxbeforeUrl.ToString().Trim(), @"\s", "");
                            currenturl2 = Regex.Replace(Par_A_wxbeforeUrl2.ToString().Trim(), @"\s", "");
                            currenturl3 = Regex.Replace(Par_A_wxbeforeUrl3.ToString().Trim(), @"\s", "");
                            currenturl4 = Regex.Replace(Par_A_wxbeforeUrl4.ToString().Trim(), @"\s", "");
                        }
                        else if (sort == 5)
                        {
                            currenturl = Regex.Replace(Par_A_wxbeforeUrl.ToString().Trim(), @"\s", "");
                            currenturl2 = Regex.Replace(Par_A_wxbeforeUrl2.ToString().Trim(), @"\s", "");
                            currenturl3 = Regex.Replace(Par_A_wxbeforeUrl3.ToString().Trim(), @"\s", "");
                            currenturl4 = Regex.Replace(Par_A_wxbeforeUrl4.ToString().Trim(), @"\s", "");
                            currenturl5 = Regex.Replace(Par_A_wxbeforeUrl5.ToString().Trim(), @"\s", "");
                        }
                        #endregion
                    }
                    else if (DateTime.Now > ParStartTime && DateTime.Now < ParEndTime)
                    {
                        #region 根据选择的条数判断（活动中）URL
                        if (sort == 1)
                        {
                            currenturl = Regex.Replace(Par_A_wxUrl.ToString().Trim(), @"\s", "");//去掉链接URL的空字符串//Par_A_wxbeforeUrl;
                        }
                        else if (sort == 2)
                        {
                            currenturl = Regex.Replace(Par_A_wxUrl.ToString().Trim(), @"\s", "");
                            currenturl2 = Regex.Replace(Par_A_wxUrl2.ToString().Trim(), @"\s", "");
                        }
                        else if (sort == 3)
                        {
                            currenturl = Regex.Replace(Par_A_wxUrl.ToString().Trim(), @"\s", "");
                            currenturl2 = Regex.Replace(Par_A_wxUrl2.ToString().Trim(), @"\s", "");
                            currenturl3 = Regex.Replace(Par_A_wxUrl3.ToString().Trim(), @"\s", "");
                        }
                        else if (sort == 4)
                        {
                            currenturl = Regex.Replace(Par_A_wxUrl.ToString().Trim(), @"\s", "");
                            currenturl2 = Regex.Replace(Par_A_wxUrl2.ToString().Trim(), @"\s", "");
                            currenturl3 = Regex.Replace(Par_A_wxUrl3.ToString().Trim(), @"\s", "");
                            currenturl4 = Regex.Replace(Par_A_wxUrl4.ToString().Trim(), @"\s", "");
                        }
                        else if (sort == 5)
                        {
                            currenturl = Regex.Replace(Par_A_wxUrl.ToString().Trim(), @"\s", "");
                            currenturl2 = Regex.Replace(Par_A_wxUrl2.ToString().Trim(), @"\s", "");
                            currenturl3 = Regex.Replace(Par_A_wxUrl3.ToString().Trim(), @"\s", "");
                            currenturl4 = Regex.Replace(Par_A_wxUrl4.ToString().Trim(), @"\s", "");
                            currenturl5 = Regex.Replace(Par_A_wxUrl5.ToString().Trim(), @"\s", "");
                        }
                        #endregion
                    }
                    else
                    {
                        #region 根据选择的条数判断（活动后）URL
                        if (sort == 1)
                        {
                            currenturl = Regex.Replace(Par_A_wxafterUrl.ToString().Trim(), @"\s", "");//去掉链接URL的空字符串//Par_A_wxbeforeUrl;
                        }
                        else if (sort == 2)
                        {
                            currenturl = Regex.Replace(Par_A_wxafterUrl.ToString().Trim(), @"\s", "");
                            currenturl2 = Regex.Replace(Par_A_wxafterUrl2.ToString().Trim(), @"\s", "");
                        }
                        else if (sort == 3)
                        {
                            currenturl = Regex.Replace(Par_A_wxafterUrl.ToString().Trim(), @"\s", "");
                            currenturl2 = Regex.Replace(Par_A_wxafterUrl2.ToString().Trim(), @"\s", "");
                            currenturl3 = Regex.Replace(Par_A_wxafterUrl3.ToString().Trim(), @"\s", "");
                        }
                        else if (sort == 4)
                        {
                            currenturl = Regex.Replace(Par_A_wxafterUrl.ToString().Trim(), @"\s", "");
                            currenturl2 = Regex.Replace(Par_A_wxafterUrl2.ToString().Trim(), @"\s", "");
                            currenturl3 = Regex.Replace(Par_A_wxafterUrl3.ToString().Trim(), @"\s", "");
                            currenturl4 = Regex.Replace(Par_A_wxafterUrl4.ToString().Trim(), @"\s", "");
                        }
                        else if (sort == 5)
                        {
                            currenturl = Regex.Replace(Par_A_wxafterUrl.ToString().Trim(), @"\s", "");
                            currenturl2 = Regex.Replace(Par_A_wxafterUrl2.ToString().Trim(), @"\s", "");
                            currenturl3 = Regex.Replace(Par_A_wxafterUrl3.ToString().Trim(), @"\s", "");
                            currenturl4 = Regex.Replace(Par_A_wxafterUrl4.ToString().Trim(), @"\s", "");
                            currenturl5 = Regex.Replace(Par_A_wxafterUrl5.ToString().Trim(), @"\s", "");
                        }
                        #endregion
                    }
                    if (Par_Chre_Source.IsNullOrEmpty())
                    {
                        JscriptMsg("子来源不能为空！", "", "Error");
                    }
                    if (Par_Appoint_Code.IsNullOrEmpty())
                    {
                        JscriptMsg("指定代码不能为空！", "", "Error");
                    }
                    var ssacode = "";
                    if (currenturl.Contains("?") || currenturl2.Contains("?") || currenturl3.Contains("?") || currenturl4.Contains("?") || currenturl5.Contains("?"))
                    {
                        ssacode = "$sacode=" + Regex.Replace(parsacode.ToString().Trim(), @"\s", "");
                    }
                    else
                    {
                        ssacode = "?sacode=" + Regex.Replace(parsacode.ToString().Trim(), @"\s", "");
                    }
                    #endregion

                    #region 组装消息
                    var sceneid = 0;
                    qr_QrCodeType type = qr_QrCodeTypeService.Instance.Get_SingleEntity_byWhere(qr_QrCodeType._.QrCodeTypeID == 1000);
                    sceneid = type.QT_CurrentIndex.ConvertTo<int>() + 1;
                    if (sort > 0)
                    {
                        #region 单图文
                        if (sort == 1)
                        {
                            extra = new List<ShareMarking.Interface.extra>() { 
                                    new ShareMarking.Interface.extra { 
                                        title = Par_A_wxTitle, 
                                        shortdesc = Par_A_wxDesc, 
                                        linkurl = (currenturl).Replace('&','$'),
                                        picurl =diyhttp+ Par_A_wxImgUrl
                                    }
                                };
                        }
                        #endregion

                        #region 双图文
                        else if (sort == 2)
                        {
                            extra = new List<ShareMarking.Interface.extra>() { 
                                        new ShareMarking.Interface.extra { 
                                            title = Par_A_wxTitle, 
                                            shortdesc = Par_A_wxDesc, 
                                            linkurl = (currenturl).Replace('&','$'),
                                            picurl =diyhttp+ Par_A_wxImgUrl
                                        },
                                        new ShareMarking.Interface.extra { 
                                            title = Par_A_wxTitle2, 
                                            shortdesc = Par_A_wxDesc2, 
                                            linkurl = (currenturl2).Replace('&','$'),
                                            picurl =diyhttp+ Par_A_wxImgUrl2
                                        }
                                    };
                        }
                        #endregion

                        #region 三图文
                        else if (sort == 3)
                        {
                            extra = new List<ShareMarking.Interface.extra>() { 
                                    new ShareMarking.Interface.extra { 
                                        title = Par_A_wxTitle, 
                                        shortdesc = Par_A_wxDesc, 
                                        linkurl = (currenturl).Replace('&','$'),
                                        picurl =diyhttp+ Par_A_wxImgUrl
                                    },
                                    new ShareMarking.Interface.extra { 
                                        title = Par_A_wxTitle2, 
                                        shortdesc = Par_A_wxDesc2, 
                                        linkurl = (currenturl2).Replace('&','$'),
                                        picurl =diyhttp+ Par_A_wxImgUrl2
                                    },
                                    new ShareMarking.Interface.extra { 
                                        title = Par_A_wxTitle3, 
                                        shortdesc = Par_A_wxDesc3, 
                                        linkurl = (currenturl3).Replace('&','$'),
                                        picurl =diyhttp+ Par_A_wxImgUrl3
                                    }
                                };
                        }
                        #endregion

                        #region 四图文
                        else if (sort == 4)
                        {
                            extra = new List<ShareMarking.Interface.extra>() { 
                                    new ShareMarking.Interface.extra { 
                                        title = Par_A_wxTitle, 
                                        shortdesc = Par_A_wxDesc, 
                                        linkurl = (currenturl).Replace('&','$'),
                                        picurl =diyhttp+ Par_A_wxImgUrl
                                    },
                                    new ShareMarking.Interface.extra { 
                                        title = Par_A_wxTitle2, 
                                        shortdesc = Par_A_wxDesc2, 
                                        linkurl = (currenturl2).Replace('&','$'),
                                        picurl =diyhttp+ Par_A_wxImgUrl2
                                    },
                                    new ShareMarking.Interface.extra { 
                                        title = Par_A_wxTitle3, 
                                        shortdesc = Par_A_wxDesc3, 
                                        linkurl = (currenturl3).Replace('&','$'),
                                        picurl =diyhttp+ Par_A_wxImgUrl3
                                    },
                                    new ShareMarking.Interface.extra { 
                                        title = Par_A_wxTitle4, 
                                        shortdesc = Par_A_wxDesc4, 
                                        linkurl = (currenturl4).Replace('&','$'),
                                        picurl =diyhttp+ Par_A_wxImgUrl4
                                    }
                                };
                        }
                        #endregion

                        #region 五图文
                        else if (sort == 5)
                        {
                            extra = new List<ShareMarking.Interface.extra>() { 
                                    new ShareMarking.Interface.extra { 
                                        title = Par_A_wxTitle, 
                                        shortdesc = Par_A_wxDesc, 
                                        linkurl = (currenturl).Replace('&','$'),
                                        picurl =diyhttp+ Par_A_wxImgUrl
                                    },
                                    new ShareMarking.Interface.extra { 
                                        title = Par_A_wxTitle2, 
                                        shortdesc = Par_A_wxDesc2, 
                                        linkurl = (currenturl2).Replace('&','$'),
                                        picurl =diyhttp+ Par_A_wxImgUrl2
                                    },
                                    new ShareMarking.Interface.extra { 
                                        title = Par_A_wxTitle3, 
                                        shortdesc = Par_A_wxDesc3, 
                                        linkurl = (currenturl3).Replace('&','$'),
                                        picurl =diyhttp+ Par_A_wxImgUrl3
                                    },
                                    new ShareMarking.Interface.extra { 
                                        title = Par_A_wxTitle4, 
                                        shortdesc = Par_A_wxDesc4, 
                                        linkurl = (currenturl4).Replace('&','$'),
                                        picurl =diyhttp+ Par_A_wxImgUrl4
                                    },
                                    new ShareMarking.Interface.extra { 
                                        title = Par_A_wxTitle5, 
                                        shortdesc = Par_A_wxDesc5, 
                                        linkurl = (currenturl5).Replace('&','$'),
                                        picurl =diyhttp+ Par_A_wxImgUrl5
                                    }
                                };
                        }
                        #endregion

                    }
                    var message = new ShareMarking.Interface.message2()
                    {
                        id = entity.A_wxQrCodeID,
                        title = Par_A_Name,
                        remark = Par_A_Name + "的二维码",
                        sacode = "test",
                        extra = extra
                    };
                    #endregion

                    #region vigo接口申请
                    var vigo = new ShareMarking.Interface.Qrcode_vigo(httpstr, signsecret);
                    var resultentity = vigo.UpdateQrcode(message);
                    if (resultentity.IndexOf("成功") > 0)
                    {
            
                        #region 修改关联成删除
                        relate.DateModified = DateTime.Now;
                        relate.Chre_Source = Par_Chre_Source;//20170612需求新增子来源、指定代码字段
                        relate.Appoint_Code = Par_Appoint_Code;
                        qr_QrCodeRelateService.Instance.Update_Entity(relate);
                        #endregion                     
                    }
                    else
                    {
                        result=false;
                        ComLib.LogLib.Log4NetBase.Log("3、====修改微信活动二维码失败：：：ActivityID：：" + entity.ActivityID + "::==结果：==::" + result);
                    }
                    #endregion

                    #region 更新多图文活动
                    if (alist.Count > 0)
                    {
                        for (int i = 0; i < alist.Count; i++)
                        {
                            if (alist[i].Sortnumber == 2)
                            {
                                #region 更新第二条图文活动
                                var entity2 = new qr_MoreActivity();
                                entity2.id = alist[i].ID;//组装的多图文ID
                                entity2.MA_wxTitle = Par_A_wxTitle2;
                                entity2.MA_wxImgUrl = Par_A_wxImgUrl2;
                                entity2.MA_wxDesc = Par_A_wxDesc2;
                                entity2.MA_wxUrl = Par_A_wxUrl2;
                                entity2.MA_wxbeforeUrl = Par_A_wxbeforeUrl2;
                                entity2.MA_wxafterUrl = Par_A_wxafterUrl2;
                                entity2.MA_currentUrl = currenturl2;//当前时间的currurl
                                entity2.DateModified = DateTime.Now;
                                qr_MoreActivityService.Instance.Update_Entity(entity2);
                                #endregion
                            }
                            else if (alist[i].Sortnumber == 3)
                            {
                                #region 保存第三条图文活动
                                var entity3 = new qr_MoreActivity();
                                entity3.id = alist[i].ID;
                                entity3.MA_wxTitle = Par_A_wxTitle3;
                                entity3.MA_wxImgUrl = Par_A_wxImgUrl3;
                                entity3.MA_wxDesc = Par_A_wxDesc3;
                                entity3.MA_wxUrl = Par_A_wxUrl3;
                                entity3.MA_wxbeforeUrl = Par_A_wxbeforeUrl3;
                                entity3.MA_wxafterUrl = Par_A_wxafterUrl3;
                                entity3.MA_currentUrl = currenturl3;//当前时间的currurl
                                entity3.DateModified = DateTime.Now;
                                qr_MoreActivityService.Instance.Update_Entity(entity3);
                                #endregion
                            }
                            else if (alist[i].Sortnumber == 4)
                            {
                                #region 更新第四条图文活动
                                var entity4 = new qr_MoreActivity();
                                entity4.id = alist[i].ID;
                                entity4.MA_wxTitle = Par_A_wxTitle4;
                                entity4.MA_wxImgUrl = Par_A_wxImgUrl4;
                                entity4.MA_wxDesc = Par_A_wxDesc4;
                                entity4.MA_wxUrl = Par_A_wxUrl4;
                                entity4.MA_wxbeforeUrl = Par_A_wxbeforeUrl4;
                                entity4.MA_wxafterUrl = Par_A_wxafterUrl4;
                                entity4.MA_currentUrl = currenturl4;//当前时间的currurl
                                entity4.DateModified = DateTime.Now;
                                qr_MoreActivityService.Instance.Update_Entity(entity4);
                                #endregion
                            }
                            else if (alist[i].Sortnumber == 5)
                            {
                                #region 更新第一条图文活动
                                //var entity = new qr_Activity();
                                //entity.A_Name = Par_A_Name;
                                //entity.A_Desc = Par_A_Desc;
                                //entity.A_Manager = Par_A_Manager;
                                //entity.A_wxTitle = Par_A_wxTitle;
                                //entity.A_wxImgUrl = Par_A_wxImgUrl;
                                //entity.A_wxDesc = Par_A_wxDesc;
                                //entity.A_wxUrl = Par_A_wxUrl;
                                //entity.A_wxbeforeUrl = Par_A_wxbeforeUrl;
                                //entity.A_wxafterUrl = Par_A_wxafterUrl;
                                //entity.A_SaCode = parsacode;
                                //entity.A_StartTime = ParStartTime;
                                //entity.A_EndTime = ParEndTime;
                                //entity.A_currentUrl = currenturl;//当前使用的URL
                                //entity.DateModified = DateTime.Now;
                                //result = qr_ActivityService.Instance.Update_Entity(entity);
                                #endregion

                                #region 更新第二条图文活动
                                //var entity2 = new qr_MoreActivity();
                                //entity2.id = alist[i].MoreActivityid;//组装的多图文ID
                                //entity2.MA_wxTitle = Par_A_wxTitle2;
                                //entity2.MA_wxImgUrl = Par_A_wxImgUrl2;
                                //entity2.MA_wxDesc = Par_A_wxDesc2;
                                //entity2.MA_wxUrl = Par_A_wxUrl2;
                                //entity2.MA_wxbeforeUrl = Par_A_wxbeforeUrl2;
                                //entity2.MA_wxafterUrl = Par_A_wxafterUrl2;
                                //entity2.MA_currentUrl = currenturl2;//当前时间的currurl
                                //entity2.DateModified = DateTime.Now;
                                //qr_MoreActivityService.Instance.Add_Entity(entity2);
                                #endregion

                                #region 更新第三条图文活动
                                //var entity3 = new qr_MoreActivity();
                                //entity3.id = alist[i].MoreActivityid;
                                //entity3.MA_wxTitle = Par_A_wxTitle3;
                                //entity3.MA_wxImgUrl = Par_A_wxImgUrl3;
                                //entity3.MA_wxDesc = Par_A_wxDesc3;
                                //entity3.MA_wxUrl = Par_A_wxUrl3;
                                //entity3.MA_wxbeforeUrl = Par_A_wxbeforeUrl3;
                                //entity3.MA_wxafterUrl = Par_A_wxafterUrl3;
                                //entity3.MA_currentUrl = currenturl3;//当前时间的currurl
                                //entity3.DateModified = DateTime.Now;
                                //qr_MoreActivityService.Instance.Add_Entity(entity3);
                                #endregion

                                #region 更新第四条图文活动
                                //var entity4 = new qr_MoreActivity();
                                //entity4.id = alist[i].MoreActivityid;
                                //entity4.MA_wxTitle = Par_A_wxTitle4;
                                //entity4.MA_wxImgUrl = Par_A_wxImgUrl4;
                                //entity4.MA_wxDesc = Par_A_wxDesc4;
                                //entity4.MA_wxUrl = Par_A_wxUrl4;
                                //entity4.MA_wxbeforeUrl = Par_A_wxbeforeUrl4;
                                //entity4.MA_wxafterUrl = Par_A_wxafterUrl4;
                                //entity4.MA_currentUrl = currenturl4;//当前时间的currurl
                                //entity4.DateModified = DateTime.Now;
                                //qr_MoreActivityService.Instance.Add_Entity(entity4);
                                #endregion

                                #region 更新第五条图文活动
                                var entity5 = new qr_MoreActivity();
                                entity5.id = alist[i].ID;
                                entity5.MA_wxTitle = Par_A_wxTitle5;
                                entity5.MA_wxImgUrl = Par_A_wxImgUrl5;
                                entity5.MA_wxDesc = Par_A_wxDesc5;
                                entity5.MA_wxUrl = Par_A_wxUrl5;
                                entity5.MA_wxbeforeUrl = Par_A_wxbeforeUrl5;
                                entity5.MA_wxafterUrl = Par_A_wxafterUrl5;
                                entity5.DateModified = DateTime.Now;
                                entity5.MA_currentUrl = currenturl5;//当前时间的currurl
                                qr_MoreActivityService.Instance.Update_Entity(entity5);
                                #endregion
                            }
                        }
                    }
                    #endregion

                    #region 更新单图文活动
                    //var entity = new qr_Activity();
                    entity.A_Name = Regex.Replace(Par_A_Name.ToString().Trim(), @"\s", ""); ;
                    entity.A_Desc = Par_A_Desc;
                    entity.A_Manager = Par_A_Manager;
                    entity.A_wxTitle = Par_A_wxTitle;
                    entity.A_wxImgUrl = Par_A_wxImgUrl;
                    entity.A_wxDesc = Par_A_wxDesc;
                    entity.A_wxUrl = Par_A_wxUrl;
                    entity.A_wxbeforeUrl = Par_A_wxbeforeUrl;
                    entity.A_wxafterUrl = Par_A_wxafterUrl;
                    entity.A_SaCode = parsacode;
                    entity.A_StartTime = ParStartTime;
                    entity.A_EndTime = ParEndTime;
                    entity.A_currentUrl = currenturl;//当前使用的URL
                    entity.DateModified = DateTime.Now;
                    result = qr_ActivityService.Instance.Update_Entity(entity);
                    #endregion
                    #endregion

                    if (result)
                    {
                        AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改qr_Activity:" + entity.ActivityID); //记录日志
                    }
                }
                else {
                    JscriptMsg("改活动不存在二维码，请核对后重试！", "", "Error");
                }
            }
            catch (Exception ex)
            {
                ComLib.LogLib.Log4NetBase.Log("修改活动二维码错误::::" + ex.Message + ex.StackTrace);
            }
            return result;
        }
        #endregion

        #region 保存按钮事件=============================

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (action == DTEnums.ActionEnum.Edit.ToString())
            { //修改
                //ChkAdminLevel("user_list", ShareMarkingEnums.ActionEnum.Edit.ToString()); //检查权限
                //if (!DoEdit(this.id))
                //{
                //    JscriptMsg("保存过程中发生错误！", "", "Error");
                //    return;
                //}
                DoEdit(this.id);
                JscriptMsg("修改成功！", "List.aspx", "Success");
            }
            else //添加
            {
                //ChkAdminLevel("user_list", ShareMarkingEnums.ActionEnum.Add.ToString()); //检查权限
                if (!DoAdd())
                {
                    JscriptMsg("保存过程中发生错误！", "", "Error");
                    return;
                }
                JscriptMsg("添加成功！", "List.aspx", "Success");
            }
        }

        #endregion

        protected void ddl_U_ImageText_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

    }
    public class listid
    {
        public string countNum;
        public List<MoreActivity> list;
    }
    public class MoreActivity
    {
        public int ID;  //id   
        public int Sortnumber;//第几条
    }

}